<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表-{$system['name']}后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/admin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <script src="/static/common/js/jquery.min.js"></script>
    <style>
        .filtrate-warp{
            margin-bottom: 10px;
        }

        .filtrate-warp .title{
            padding: 5px 12px 7px 12px;
            font-size: 14px;
            font-weight: normal;
            text-align: left;
            cursor: pointer;
            width: 90px;
            background-color: transparent!important;
            color: black!important;
        }

        .filtrate-warp .title:hover{
            color: black;
        }

        .filtrate-warp .flag{
            padding: 6px 12px 6px 12px;
            cursor: pointer;
        }

        .filtrate-warp .flag:hover{
            color: black;
        }

        .filtrate-warp .layui-badge:hover{
            color: white!important;
        }

    </style>

</head>
<body >

<div class="admin-main layui-anim layui-anim-upbit">


    <fieldset class="layui-elem-field " >
        <legend>高级查询</legend>

        <div class="layui-card" style="box-shadow: none;margin-top: 10px">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-bottom: transparent;height: auto" >

                <div class="layui-form-item" style="text-align: left;padding-left: 20px;">



                    <div class="layui-inline">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="">请选择审核状态：</option>
                                <option value="待审核">待审核</option>
                                <option value="审核通过">审核通过</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">时间查询：</label>
                        <div class="layui-input-inline">
                            <select name="timebucket">
                                <option value="">请选择时间</option>
                                <option value="today">今天</option>
                                <option value="yesterday">昨天</option>
                                <option value="week">本周</option>
                                <option value="last week">上周</option>
                                <option value="month">本月</option>
                                <option value="last month">上月</option>
                                <option value="year">今年</option>
                                <option value="last year">去年</option>
                                <option value="-2 hours">两个小时内</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="">客户名称：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="cname" name="cname" placeholder="请输入客户名称" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">业务员：</label>
                        <div class="layui-input-inline">
                            <select name="pr_user" id="pr_user">
                                <option value="">请选择业务员</option>

                                {volist name='adminResult' id='vo'}
                                <option value="{$vo.username}">{$vo.realname}</option>
                                {/volist}

                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">手机：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" placeholder="请输入手机号码" class="layui-input">
                        </div>
                    </div>

                </div>
                <div class="layui-inline" style="float: right;padding-bottom: 15px">
                    <button class="layui-btn layuiadmin-btn-list"  lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"  style="vertical-align: sub;"></i>查询数据
                    </button>
                </div>

            </div>
        </div>
    </fieldset>
    <table class="layui-table" id="table-list" lay-filter="table-list"></table>
</div>
<script type="text/html" id="action">
   <!-- <?php  if(auth('Order/editAudit')){ ?>
    {{# if(d.status=='待审核'){ }}
<a class="layui-btn  layui-btn-xs" lay-event="editAudit"><i class="layui-icon">&#xe642;</i>审核订单</a>
{{# } }}
<?php } ?>-->

    <?php  if(auth('Order/del')){ ?>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
    <?php } ?>
   
</script>


<script type="text/html" id="topBtn">
    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius layui-btn-sm" id="add"><i class="layui-icon">&#xe608;</i>添加订单</button>
</script>


{include file="common/foot"/}
<script>
    layui.use(['table','form','upload','util','laydate'], function() {
        var table = layui.table,form = layui.form,laydate = layui.laydate, $ = layui.jquery,upload = layui.upload,util = layui.util;
        var tableIn = table.render({
            elem: '#table-list',
            url: '{:url("index")}',
            method: 'post',
            toolbar: '#topBtn',
            defaultToolbar:['filter','print','exports'],
            cols: [[
                {checkbox:true,fixed: true},
                {field: 'id', title: 'ID',  fixed: true,hide:true},
                {field: 'cname', title: '客户名称'},
                {field: 'cphone', title: '联系号码', },
                {field: 'money', title: '业绩', },
                //{field: 'freight', title: '运费', },
                {field: 'return_money', title: '回款', },
                {field: 'realname', title: '负责人',hide:false },
                {field: 'remark', title: '备注', },
                {field: 'status', title: '审核状态', },
                 {field: 'create_time', title: '创建时间', },
                {width: 220, title:'操作',align: 'center',  toolbar: '#action'}
            ]],
            limit: {$system['more']['admin_pagesize']}, //每页默认显示的数量

            page: {limits:[10, 20, 30, 40, 50,100,1000]},
        });

        function postShenhe(data,index){
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('editAudit')}",{id:data['id'],status:data['status']},function(res){
                layer.close(loading);
                if(res.code===0){
                    layer.msg(res.msg,{time:2000,icon:1});
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:2000,icon:2});
                }
            });
            layer.close(index);
        }
        table.on('tool(table-list)', function(obj) {
            var data = obj.data;

            if (obj.event === 'del') {
                layer.confirm('您确定要删除这个客户吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===0){
                            layer.msg(res.msg,{time:2000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:2000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            else if(obj.event === 'edit'){
                layer_add("编辑客户","{:url('Order/edit')}?id="+data.id);
            }
            else if(obj.event === 'editAudit'){
                layer.confirm('确认金额和客户信息,确认审核业绩吗？',{ btn: ['审核通过', '审核不通过','取消'] ,btn3: function(index, layero){
                            //按钮【按钮三】的回调
                            layer.close(index);
                        }}, function(index){
                        //按钮【按钮一】的回调
                        postShenhe({id:data.id,status:1},index);
                    },function(index){
                        //按钮【按钮二】的回调
                        postShenhe({id:data.id,status:-1},index);
                    }
                );
            }
        });


        $('body').on('click','#add',function() {
            var indexOpen = layer.open({
                type: 2,
                title: '添加订单',
                closeBtn: 1, //是否显示关闭按钮
                area: ['100%','86%'],
                anim: 2,  //动画
                shadeClose: false,  //点击空白处是否关闭
                maxmin: false, //开启最大化最小化按钮
                content: ["{:url('add')}"]
            });
        })



        //监听事件
        table.on('toolbar(table-list)', function(obj){

            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'moveGh':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        console.log(data);
                        /*layer.alert('编辑 [id]：'+ checkStatus.data[0]['id']);*/
                        var indexOpen = layer.open({
                            type: 2,
                            title: '移入公海',
                            closeBtn: 1, //是否显示关闭按钮
                            area: ['100%','86%'],
                            anim: 2,  //动画
                            shadeClose: false,  //点击空白处是否关闭
                            maxmin: false, //开启最大化最小化按钮
                            content: ["{:url('Client/toMoveGh')}?id="+checkStatus.data[0]['id']]
                        });
                    }
                    break;
                case 'alterAll':
                    var checkStatus = table.checkStatus(obj.config.id)
                        ,data=checkStatus.data;//获取选中的数据

                    if(data.length > 0){
                        alterList = [];  //定义需要转移的数组
                        data.forEach(function (obj,index) {
                            alterList.push(obj.id);
                        });

                        var currConfirm = layer.confirm('您确定要转移这'+data.length+'个客户吗？',function (index) {


                            layer.close(currConfirm);
                            var indexOpen = layer.open({
                                type: 2,
                                title: '转移客户',
                                closeBtn: 1, //是否显示关闭按钮
                                area: ['100%','86%'],
                                anim: 2,  //动画
                                shadeClose: false,  //点击空白处是否关闭
                                maxmin: false, //开启最大化最小化按钮
                                content: ["{:url('Client/alterPrUser')}?ids="+alterList]

                            });


                        });


                    }else {
                        layer.msg("请选择需要转移的客户");
                    }
                    break;
            };
        });


    //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            table.reload('table-list', {
                url:"{:url('Order/clientSearch')}",
                where: {
                    keyword: data.field
                },
                page:{
                    curr:1
                }
            });


        });

        laydate.render({
            elem: '#create_time'
        });

    });
</script>


<script>

    /*添加*/
    function layer_add(title,url){
        var index = layer.open({
            type: 2,
            title: title,
            closeBtn: 1, //是否显示关闭按钮
            area: ['100%','86%'],
            anim: 2,  //动画
            shadeClose: false,  //点击空白处是否关闭
            maxmin: true, //开启最大化最小化按钮
            content: [url]
        });
    }

</script>

</body>
</html>